using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace MaterialUI
{
	[AddComponentMenu("MaterialUI/Tab Item", 100)]
	public class TabItem : Selectable, IPointerClickHandler, ISubmitHandler, IEventSystemHandler
	{
		[SerializeField]
		private Text m_ItemText;

		[SerializeField]
		private Graphic m_ItemIcon;

		[SerializeField]
		private TabView m_TabView;

		private int m_Id;

		private RectTransform m_RectTransform;

		private CanvasGroup m_CanvasGroup;

		public Text itemText
		{
			get
			{
				return m_ItemText;
			}
			set
			{
				m_ItemText = value;
			}
		}

		public Graphic itemIcon
		{
			get
			{
				return m_ItemIcon;
			}
			set
			{
				m_ItemIcon = value;
			}
		}

		public TabView tabView
		{
			get
			{
				return m_TabView;
			}
			set
			{
				m_TabView = value;
			}
		}

		public int id
		{
			get
			{
				return m_Id;
			}
			set
			{
				m_Id = value;
			}
		}

		public RectTransform rectTransform
		{
			get
			{
				if (m_RectTransform == null)
				{
					m_RectTransform = (RectTransform)base.transform;
				}
				return m_RectTransform;
			}
		}

		public CanvasGroup canvasGroup
		{
			get
			{
				if (m_CanvasGroup == null)
				{
					m_CanvasGroup = base.gameObject.GetComponent<CanvasGroup>();
				}
				return m_CanvasGroup;
			}
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			if (base.interactable)
			{
				m_TabView.SetPage(id);
			}
		}

		public override void OnPointerDown(PointerEventData eventData)
		{
			base.OnPointerDown(eventData);
			if (base.interactable)
			{
				m_TabView.TabItemPointerDown(id);
			}
		}

		public void OnSubmit(BaseEventData eventData)
		{
			if (base.interactable)
			{
				m_TabView.SetPage(id);
			}
		}

		public void SetupGraphic(ImageDataType type)
		{
			if (!(base.gameObject.GetChildByName<Image>("Icon") == null) && !(base.gameObject.GetChildByName<VectorImage>("Icon") == null))
			{
				if (type == ImageDataType.Sprite)
				{
					m_ItemIcon = base.gameObject.GetChildByName<Image>("Icon");
					UnityEngine.Object.Destroy(base.gameObject.GetChildByName<VectorImage>("Icon").gameObject);
				}
				else
				{
					m_ItemIcon = base.gameObject.GetChildByName<VectorImage>("Icon");
					UnityEngine.Object.Destroy(base.gameObject.GetChildByName<Image>("Icon").gameObject);
				}
			}
		}
	}
}
